#pragma once

#include "base/event_loop.h"
#include "ice/candidate.h"
#include "ice/stun.h"

namespace xrtc {

class UDPPort;

class IceConnection {
public:
    IceConnection(EventLoop* el, UDPPort* port, const Candidate& remote_candidate);
    ~IceConnection() = default;

    const Candidate& get_remote_candidate() const { return m_remote_candidate; }

    void on_read_packet(const char* buf, size_t len, int64_t ts);

    // 处理STUN Binding请求
    void handle_stun_binding_request(StunMessage* stun_msg);
    // 构建响应包，并调用 send_response_message 发送STUN Binding响应
    void send_stun_binding_response(StunMessage* stun_msg); 
    // 发送响应消息
    void send_response_message(const StunMessage& response);

    std::string to_string();

private:
    EventLoop* m_el;
    UDPPort* m_port;
    Candidate m_remote_candidate;
};

} // namespace xrtc